<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var deleteNode = function (head, val) {
      let pre = head
      let cur = head.next
      if (pre.val === val) return cur
      while (pre !== null && pre.next !== null) {
        if (cur.val === val) {
          pre.next = cur.next
        }
        pre = pre.next
        cur = cur.next
      }
      return head
    };
    console.log(deleteNode(head = [4, 5, 1, 9], val = 5
    ));
  </script>

</body>

</html>